package Market;

import java.io.Serializable;

public class QuotaData implements Serializable {

    private static final long serialVersionUID = 1L;
    private double average;
    private double rate;
    private double lastPrice;
    private Long count;

    public QuotaData() {
        average = 0;
        rate = 0;
        lastPrice = 0;
        count = 0L;
    }

    public void add(double nowValue) {
        this.average = (this.average * count + nowValue) / (count + 1);
        ++count;
        if (lastPrice != 0) {
            rate = (nowValue - lastPrice) / lastPrice;
        }
        lastPrice = nowValue;
    }

    public String toString() {
        return String.format("average:%g, rate:%g, lastPrice:%g, count: %d\n", average, rate, lastPrice, count);
    }

}
